/*********************************************************
 *  Copyright (c) 2011 by Web Information Systems (WIS) Group, 
 *  Delft University of Technology.
 *  Qi Gao, http://wis.ewi.tudelft.nl/index.php/home-qi-gao
 *  
 *  Some rights reserved.
 *
 *  Contact: q.gao@tudelft.nl
 *
 **********************************************************/
package org.persweb.genius.weight;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.persweb.genius.model.Concept;
import org.persweb.genius.model.Item;

/**
 * @author Qi Gao <a href="mailto:q.gao@tudelft.nl">q.gao@tudelft.nl</a>
 * @version created on Sep 6, 2011 9:32:42 AM
 */
public class TF implements WeightFunction {

	public Collection<Item> items = null;	
	
	/**
	 * 
	 */
	public TF() {
		super();
	}

	/**
	 * @param items
	 */
	public TF(Collection<Item> items) {
		super();
		this.items = items;
	}

	/* (non-Javadoc)
	 * @see org.persweb.genius.weight.WeightFunction#calculateWeights(java.util.Collection)
	 */
	@Override
	public Map<Concept, Double> calculateWeights(Collection<Item> items) {
		Map<Concept, Double> weightedConcepts = new HashMap<Concept, Double>();
		// based occurrence times of the items
		for (Item item : items) {
			for (Concept concept : item.getConcepts()) {
				if (weightedConcepts.containsKey(concept)) {
					// System.out.println("concept repeated");
					weightedConcepts.put(concept,
							weightedConcepts.get(concept) + 1.0);
				} else {
					weightedConcepts.put(concept, 1.0);
				}
			}
		}
		return weightedConcepts;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "TF";
	}
	
	
}
